/**
 * Generates backend configuration file content
 *
 * @param adapterChoice - The database adapter to use ('kysely-postgres', 'kysely-sqlite', or 'memory')
 * @param connectionString - Connection string for database (for 'kysely-postgres')
 * @param filePath - Path to the database file (for 'kysely-sqlite')
 * @returns The generated backend configuration file content
 */
export function generateBackendConfigContent(
	adapterChoice: string,
	connectionString?: string,
	filePath?: string
): string {
	let adapterImport = '';
	let adapterConfig = '';

	switch (adapterChoice) {
		case 'kysely-postgres': {
			adapterImport = `import { kyselyAdapter } from '@c15t/backend/db/adapters/kysely';\nimport { PostgresDialect } from 'kysely';\nimport { Pool } from 'pg';`;
			adapterConfig = `kyselyAdapter({
      dialect: new PostgresDialect({
        pool: new Pool({
          connectionString: ${connectionString ? `"${connectionString}"` : 'process.env.DATABASE_URL || "postgresql://user:password@host:port/db"'}
        })
      })
    })`;
			break;
		}
		case 'kysely-sqlite': {
			adapterImport = `import { kyselyAdapter } from '@c15t/backend/db/adapters/kysely';\nimport { SqliteDialect } from 'kysely';\nimport Database from 'better-sqlite3';`;
			adapterConfig = `kyselyAdapter({
      dialect: new SqliteDialect({
        database: new Database("${filePath || './db.sqlite'}")
      })
    })`;
			break;
		}
		default: {
			adapterImport = `import { memoryAdapter } from '@c15t/backend/db/adapters/memory';`;
			adapterConfig = 'memoryAdapter({})';
			break;
		}
	}

	return `// c15t Backend Configuration
// Generated by c15t CLI onboarding

import { c15tInstance } from '@c15t/backend';
${adapterImport}

// WARNING: Database connection strings often contain sensitive credentials.
// Consider using environment variables instead of hardcoding these values.

// Define your c15t instance
const instance = c15tInstance({
  appName: 'Your App Name',
  basePath: '/api/c15t',
  database: ${adapterConfig},
  trustedOrigins: ['http://localhost:3000'],
});

export default instance;
`;
}
